//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.lyq.bean.service;

import com.lyq.bean.Course;
import com.lyq.bean.Elective;
import com.lyq.bean.Student;
import com.lyq.bean.Teacher;
import com.lyq.bean.mySql.GetElective_Sql;
import com.lyq.bean.mySql.Grade_Sql;
import com.lyq.bean.mySql.SeekElectStuentNo_Sql;
import com.lyq.bean.mySql.SeekTeachC_Sql;

import java.util.ArrayList;
import java.util.List;

public class TC_Service {
    public TC_Service() {
    }

    public List<Course> getTeachC(String tNo) {
        List<Course> list = new ArrayList();
        List<Teacher> tlist = new ArrayList();
        tlist = (new T_Service()).seek_T("工号", "精确查询", tNo, tlist);

        for(int i = 0; i < tlist.size(); ++i) {
            String teacherId = ((Teacher)tlist.toArray()[i]).getNo();
            list = (new SeekTeachC_Sql()).seekTeachC_Sql(teacherId, (List)list);
        }

        return (List)list;
    }

    public List<Student> seekElectS(String cNo) {
        List<Student> list = new ArrayList<>();

        // 获取选课学生的学号列表
        List<Elective> electives = (new SeekElectStuentNo_Sql()).seekElectStuentNo_Sql(cNo);

        // 收集所有学号
        List<String> studentNos = new ArrayList<>();
        for (Elective elective : electives) {
            studentNos.add(elective.getsNo());
        }

        // 如果没有学生选课，直接返回空列表
        if (studentNos.isEmpty()) {
            return list;
        }

        // 一次性查询所有选课学生的信息
        for (String sNo : studentNos) {
            List<Student> students = (new S_Service()).seek_S("学号", "精确查询", sNo, new ArrayList<>());
            if (!students.isEmpty()) {
                list.add(students.get(0));
            }
        }

        return list;
    }

    public Elective getElective(String cNo, String sNo) {
        new Elective();
        Elective e = (new GetElective_Sql()).getElective_Sql(cNo, sNo);
        return e;
    }

    public Boolean grade(String cNo, String sNo, String grade) {
        Boolean bool = (new Grade_Sql()).grade_Sql(cNo, sNo, grade);
        return bool;
    }

    public List<Student> SeekAllMyStudent(String tNo) {
        List<Student> list = new ArrayList();
        new ArrayList();
        List<Course> clist = (new TC_Service()).getTeachC(tNo);

        for(int i = 0; i < clist.size(); ++i) {
            String cNo = ((Course)clist.toArray()[i]).getNo();
            List<Student> slist = (new TC_Service()).seekElectS(cNo);
            list.addAll(slist);
        }

        return list;
    }

    public List<Student> SeekMyStudent(String tNo, String select, String seek, String name) {
        List<Student> list = new ArrayList();
        new ArrayList();
        List<Student> allList = (new TC_Service()).SeekAllMyStudent(tNo);
        List<Student> seekList = new ArrayList();
        seekList = (new S_Service()).seek_S(select, seek, name, seekList);

        for(int i = 0; i < seekList.size(); ++i) {
            for(int j = 0; j < allList.size(); ++j) {
                Student s1 = (Student)seekList.toArray()[i];
                Student s2 = (Student)allList.toArray()[j];
                if (s1.getNo().equals(s2.getNo())) {
                    list.add(s2);
                }
            }
        }

        return list;
    }
}
